import 'package:flutter/material.dart';
import 'package:xindong/models/user/xindong_user.dart';
import 'package:xindong/utils/xindong_image_util.dart';

Widget XinDongAvatar({required String? url, double size = 32, double? radius, Function()? onTap}) {
  return GestureDetector(
    onTap: onTap,
    behavior: HitTestBehavior.opaque,
    child: Container(
      width: size,
      height: size,
      clipBehavior: Clip.antiAlias,
      decoration: BoxDecoration(borderRadius: BorderRadius.circular(radius ?? size)),
      child: ImageUtil.avatarUrl(url),
    ),
  );
}

Widget XinDongAvatarBorder(
  XinDongUser? user, {
  double avatarSize = 32,
  double borderWidth = 2.0,
  Color borderColor = Colors.white,
  Function()? onTap,
}) {
  return GestureDetector(
    onTap: onTap,
    behavior: HitTestBehavior.opaque,
    child: Container(
      width: avatarSize,
      height: avatarSize,
      clipBehavior: Clip.antiAlias,
      decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(avatarSize),
          border: Border.all(color: borderColor, width: borderWidth),
          color: borderColor),
      child: ClipRRect(borderRadius: BorderRadius.circular(avatarSize), child: ImageUtil.avatarUrl(user?.getAvatar)),
    ),
  );
}
